﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace BaoVeBienCuong.Store
{
    public class ButtonMenu
    {
        private int Type;
        //0 : batdau, 1 : cai dat, 2 :thanh tich
        //3 : download, 4 : share , 5 : infor , 6: off
        //7 : rate
        private Vector2 position;
        private Vector2 size;
        private Texture2D image;
        int second;
        private bool isSelect;
        private float scale = 2.0f / 3.0f;

        public ButtonMenu(int type)
        {
            Type = type;
            if (Type <= 2)
                size = new Vector2(360, 112) * scale;
            else if (Type > 2)
                size = new Vector2(87, 87) * scale;

            isSelect = false;
        }
        public void setScale(float f)
        {
            scale = f;
        }
        public void setType(int type)
        {
            Type = type;
            if (Type <= 2)
                position = new Vector2(550, 20 + Type * 90);
            else
                position = new Vector2(230 + Type * 70, Type % 2 == 0 ? 370 : 420);
        }
        public void Load(ContentManager content)
        {
            if (Type <= 2)
            {
                image = content.Load<Texture2D>("images/menu/menuButton");
            }
            else
            {
                if (Type == 7)
                {
                    image = content.Load<Texture2D>("images/menu/rate");
                }
                else
                {
                    image = content.Load<Texture2D>("images/menu/standardButton");
                }
            }
        }
        public void Draw(SpriteBatch sprite)
        {
            if (isSelect)
                second++;
            //if (Type == 1) isSelect = false;
            if (second == 10 && Type != 1 && Type != 5)
            {
                isSelect = false;
                second = 0;
            }
            #region
            if (Type == 0)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(183, 0, 183, 56), Color.White, 0.0f, Vector2.Zero, scale * 2, SpriteEffects.None, 1.0f);

                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 0, 183, 56), Color.White, 0.0f, Vector2.Zero, scale * 2, SpriteEffects.None, 1.0f);

                }
            }
            else if (Type == 1)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(183, 56, 183, 56), Color.White, 0.0f, Vector2.Zero, scale * 2, SpriteEffects.None, 1.0f);

                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 56, 183, 56), Color.White, 0.0f, Vector2.Zero, scale * 2, SpriteEffects.None, 1.0f);

                }
            }
            else if (Type == 2)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(183, 112, 183, 56), Color.White, 0.0f, Vector2.Zero, scale * 2, SpriteEffects.None, 1.0f);

                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 112, 183, 56), Color.White, 0.0f, Vector2.Zero, scale * 2, SpriteEffects.None, 1.0f);

                }
            }

            #endregion
            #region
            else if (Type == 3)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 87, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 87, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            else if (Type == 4)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 174, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 174, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            else if (Type == 5)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 261, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 261, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            else if (Type == 6)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 348, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 348, 87, 87), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            else if (Type == 7)
            {
                if (isSelect)
                {
                    sprite.Draw(image, position, new Rectangle(87, 0, 87, 89), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
                else
                {
                    sprite.Draw(image, position, new Rectangle(0, 0, 87, 89), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1.0f);
                }
            }
            #endregion
        }
        public bool isTouch(Vector2 posi)
        {
            isSelect = false;
            if (posi.X >= position.X && posi.X <= (position.X + size.X) && posi.Y >= position.Y && posi.Y <= (position.Y + size.Y))
            {
                isSelect = true;

                return true;
            }
            else
            {
                return false;
            }
        }
        public void setTouch(bool x)
        {
            isSelect = x;
        }
    }
}
